﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using XYS.MISS.Photo.PhotoAdmin;

namespace WpfWeather
{
    /// <summary>
    /// UserControl1.xaml 的交互逻辑
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        public string webpath = "http://www.cma.gov.cn/tqyb/img/weather/";

        private string daystr = "今天";

        private string _city = "";
        public string City
        {
            get { return _city; }
            set
            {
                _city = value;
            }
        }

        public UserControl1()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            //GetWeatherByWebService.WeatherWebService getWeather = new GetWeatherByWebService.WeatherWebService();

            WeatherWebService getWeather = new WeatherWebService();

            string[] weatherinfo;
            try
            {
                weatherinfo = getWeather.getWeatherbyCityName(City);

                string today = weatherinfo[4].Substring(0,weatherinfo[4].IndexOf(' ') + 1);
                string header = string.Format("{0}  {1}",weatherinfo[1],today);

                this.tbk_cityName.Text = header;

                if (daystr == "今天")
                {
                    this.tb_detail.Text = weatherinfo[10];
                    this.tb_qw.Text = weatherinfo[5];
                    this.tb_fl.Text = weatherinfo[7];
                    this.tb_tq.Text = weatherinfo[6].Substring(weatherinfo[6].LastIndexOf(" ") + 1);
                }
                else if (daystr == "明天")
                {
                    this.tb_detail.Text = "";
                    this.tb_qw.Text = weatherinfo[12];
                    this.tb_fl.Text = weatherinfo[14];
                    this.tb_tq.Text = weatherinfo[13].Substring(weatherinfo[13].LastIndexOf(" ") + 1);
                }
                else
                {
                    this.tb_detail.Text = "";
                    this.tb_qw.Text = weatherinfo[17];
                    this.tb_fl.Text = weatherinfo[19];
                    this.tb_tq.Text = weatherinfo[18].Substring(weatherinfo[18].LastIndexOf(" ") + 1);
                }

                tb_onnet.Text = "";
            }
            catch
            {
                tb_onnet.Text = "无法获得网络服务……";
            }
        }

        public string[] ToStrings()
        {
            string[] rets = new string[4];
            rets[0] = tb_tq.Text;
            rets[1] = tb_qw.Text;
            rets[2] = tb_fl.Text;
            rets[3] = tb_detail.Text;
            return rets;
        }


    }
}
